/**********************, *****************************************************************
Firm-embedded productivity and cross-country income differences
Alviarez, Cravino and Ramondo
Journal of Political Economy (2022)

Program: table_B4_lessthan3affiliates.do
Date: October 2022

Description: Reproduces Table B.4: Countries with less than 3 affiliates, by NAICS2.

*****************************************************************************************/

*-------------------------------------------------------------------------------
global typeden=1
include "set_directories.do"
set memory 64g
global lf "LF"

*Log
cap log close
log using "${clogs}/table_B4_lessthan3affiliates.log",replace
*-------------------------------------------------------------------------------


*Number of foreign affiliates with less than 3 affiliates
*---------------------------------------------------------
use "${data}/pre_reg0_naics_sales_s1_base_woparent_2016.dta", clear  

by year sector isocode guo_bvd, sort: gen a=_n==1
replace a=0 if isocode==hq
collapse (sum) num_aff=a, by(year sector isocode)
keep if num_aff<3

export delimited using "${rappendix}/table_B4_lessthan3affiliates.csv", datafmt replace

log close 
